<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Events_model extends OC_Model {

    public function get_event($id)
    {
        $this->db->where('e_id',$id);
        $this->db->order_by('e_id', 'desc');
        // return $this->db->get('events')->result();
        return $this->db->get('events')->row_array();
    }

    public function record_count() {
        return $this->db->count_all("events");
    }

    public function fetch_data($limit, $id) {
        $this->db->limit($limit);
        $this->db->where('e_id', $id);
        $query = $this->db->get("events");
        
            if ($query->num_rows() > 0) {
                foreach ($query->result() as $row) {
                $data[] = $row;
                }

                return $data;
            }
        return false;
    }

    public function fetch_countries($limit, $start) {
        $this->db->order_by('e_id', 'desc');
        $this->db->limit($limit, $start);
        $query = $this->db->get("events");
 
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }

    public function get_recent_articles()
    {
        $this->db->limit(5);
        $this->db->order_by('a_id', 'desc');
        return $this->db->get('articles')->result();
    }

    public function get_recent_products()
    {
        $this->db->limit(5);
        $this->db->order_by('p_id', 'desc');
        return $this->db->get('products')->result();
    }

    public function do_comment($object)
    {
        return $this->db->insert('comment_events', $object);
    }

    public function get_comments($id=false)
    {
        $this->db->where('e_id', $id);
        $this->db->where('ce_approved', 1);
        return $this->db->get('comment_events')->result();
    }
}

/* End of file home_model.php */
/* Location: ./applications/module_front/home/models/home_model.php */